xen/sched: fix latent races accessing vcpu->dirty_cpu
authorJuergen Gross <jgross@suse.com>
Thu, 14 May 2020 15:36:14 +0000 (17:36 +0200)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Sat, 16 May 2020 13:15:46 +0000 (14:15 +0100)
commit99266e31832fb4a4da5c9b8163328be350d1261d
treed8ed7cfa5693f0918fc886f3589d2ec125a27be6
parentb492c65da5ec5ed07974db22e998243be475a664
xen/sched: fix latent races accessing vcpu->dirty_cpu

The dirty_cpu field of struct vcpu denotes which cpu still holds data
of a vcpu. All accesses to this field should be atomic in case the
vcpu could just be running, as it is accessed without any lock held
in most cases. Especially sync_local_execstate() and context_switch()
for the same vcpu running concurrently have a risk for failing.

There are some instances where accesses are not atomically done, and
even worse where multiple accesses are done when a single one would
be mandated.

Correct that in order to avoid potential problems.

Add some assertions to verify dirty_cpu is handled properly.

Signed-off-by: Juergen Gross <jgross@suse.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
xen/arch/x86/domain.c
xen/common/keyhandler.c
xen/include/xen/sched.h